# 收敛曲线数据
epochs = np.arange(0, 151)
fedavg_acc = 85 * (1 - np.exp(-0.03 * epochs))
fedat_acc = 85 * (1 - np.exp(-0.045 * epochs))
dhaf_acc = 85 * (1 - np.exp(-0.065 * epochs))

# 绘制收敛曲线
plt.figure(figsize=(10, 6))
plt.plot(epochs, fedavg_acc, 'b--', linewidth=2, label='FedAvg (142 rounds)')
plt.plot(epochs, fedat_acc, 'g-.', linewidth=2, label='FedAT (98 rounds)')
plt.plot(epochs, dhaf_acc, 'r-', linewidth=3, label='DHA-FL (67 rounds)')

# 标注目标精度线
# plt.axhline(y=85, color='gray', linestyle=':', alpha=0.7)
# plt.text(140, 86, 'Target Accuracy (85%)', fontsize=10)

# # 标注收敛轮次
# plt.scatter([142, 98, 67], [85, 85, 85], s=80, color=['b','g','r'])
# plt.text(142, 83, '142', ha='center', fontsize=10)
# plt.text(98, 83, '98', ha='center', fontsize=10)
# plt.text(67, 83, '67', ha='center', fontsize=10)

plt.xlabel('Communication Rounds', fontsize=14)
plt.ylabel('Accuracy (%)', fontsize=14)
# plt.title('Convergence Speed Comparison', fontsize=14)
plt.legend(loc='lower right',prop={'size': 14, 'family': 'SimHei'})
plt.grid(alpha=0.3)
plt.savefig('convergence_speed_en.png', bbox_inches='tight')
